package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.SysBasic;
import com.ruoyi.system.service.ISysBasicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 基础数据Controller
 *
 * @author gzhuangwei
 * @date 2021-09-29
 */
@RestController
@RequestMapping("/system/basic")
public class SysBasicController extends BaseController
{
    @Autowired
    private ISysBasicService sysBasicService;

    /**
     * 查询基础数据列表
     */
    @PreAuthorize("@ss.hasPermi('system:basic:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysBasic sysBasic)
    {
        startPage();
        List<SysBasic> list = sysBasicService.selectSysBasicList(sysBasic);
        return getDataTable(list);
    }

    /**
     * 查询页脚信息
     */
    @GetMapping("/footer")
    public AjaxResult getFooterInfo()
    {
        SysBasic sysBasic = new SysBasic();
        sysBasic.setBasiType("footerinfo");
        List<SysBasic> list = sysBasicService.selectSysBasicList(sysBasic);
        SysBasic returnSysBasic = new SysBasic();
        returnSysBasic.setBasiData("Copyright © 2022  东莞杯工业设计大赛组委员会版权所有");
        if (list.size() > 0) {
            returnSysBasic = list.get(list.size() - 1);
        }
        return AjaxResult.success(returnSysBasic);
    }

    /**
     * 查询备案号
     */
    @GetMapping("/record")
    public AjaxResult getRecordNumber()
    {
        SysBasic sysBasic = new SysBasic();
        sysBasic.setBasiType("recordnumber");
        List<SysBasic> list = sysBasicService.selectSysBasicList(sysBasic);
        SysBasic returnSysBasic = new SysBasic();
        returnSysBasic.setBasiData("粤ICP备15018148号-1");
        if (list.size() > 0) {
            returnSysBasic = list.get(list.size() - 1);
        }
        return AjaxResult.success(returnSysBasic);
    }

    /**
     * 导出基础数据列表
     */
    @PreAuthorize("@ss.hasPermi('system:basic:export')")
    @Log(title = "基础数据", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SysBasic sysBasic)
    {
        List<SysBasic> list = sysBasicService.selectSysBasicList(sysBasic);
        ExcelUtil<SysBasic> util = new ExcelUtil<SysBasic>(SysBasic.class);
        return util.exportExcel(list, "基础数据数据");
    }

    /**
     * 获取基础数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:basic:query')")
    @GetMapping(value = "/{basiId}")
    public AjaxResult getInfo(@PathVariable("basiId") Long basiId)
    {
        return AjaxResult.success(sysBasicService.selectSysBasicById(basiId));
    }

    /**
     * 新增基础数据
     */
    @PreAuthorize("@ss.hasPermi('system:basic:add')")
    @Log(title = "基础数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysBasic sysBasic)
    {
        return toAjax(sysBasicService.insertSysBasic(sysBasic));
    }

    /**
     * 修改基础数据
     */
    @PreAuthorize("@ss.hasPermi('system:basic:edit')")
    @Log(title = "基础数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysBasic sysBasic)
    {
        return toAjax(sysBasicService.updateSysBasic(sysBasic));
    }

    /**
     * 删除基础数据
     */
    @PreAuthorize("@ss.hasPermi('system:basic:remove')")
    @Log(title = "基础数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{basiIds}")
    public AjaxResult remove(@PathVariable Long[] basiIds)
    {

        return toAjax(sysBasicService.deleteSysBasicByIds(basiIds));
    }
}
